package com.kwq.designPattern.construct.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author kangwanqiang
 * @date 2021/2/9
 */
public class ProxyClient {
    public static void main(String[] args) {
        ProxyImage image = new ProxyImage("test_10mb.jpg");

        // 图像将从磁盘加载
        image.display();
        System.out.println("");
        // 图像不需要从磁盘加载
        image.display();

        // jdk动态代理
        Image proxy = (Image) Proxy.newProxyInstance(
                RealImage.class.getClassLoader(),
                RealImage.class.getInterfaces(),
                new MyInvocationHandler(image));
        proxy.display();
    }
}
